fix: restore AvMAX empty-array guard lost in ithreads refactoring#98
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: restore AvMAX empty-array guard lost in ithreads refactoring#98Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
…ithreads refactoring) The AvMAX >= 0 guard was added in 3005451 (fixes cpan-authors#66) to prevent negative pointer arithmetic when an empty SVt_PVAV is on the stack. The ithreads refactoring (d220633/01967e6) rewrote the macro from global variables to MY_CXT and lost the guard. Without this check, `arg + AvMAX(arg)` produces `arg + (-1)` on empty arrays — undefined behavior in C that can cause memory corruption or segfaults in rare stack configurations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Restores the
AvMAX >= 0guard in the DEFGV detection macro that was lost during the ithreads refactoring.Why
Commit 3005451 added
&& AvMAX((AV*)arg) >= 0to prevent negative pointer arithmetic when an emptySVt_PVAVis on the Perl stack (fixes #66). The subsequent ithreads refactoring (d220633/01967e6) rewrote the macro to useMY_CXTand silently dropped this guard.Without the check,
arg + AvMAX(arg)computesarg + (-1)on empty arrays — undefined behavior in C that can cause memory corruption or segfaults in rare stack configurations.How
One-line fix: re-add the
AvMAX((AV*)arg) >= 0condition before the pointer arithmetic.Testing
Full test suite passes. The original fix was validated in #66; this restores identical behavior.
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 2 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (0 Tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline